unit uAppLog;

interface

procedure WriteLog(const s: string);
procedure FmtWriteLog(const fmt: string; const args: array of const);

implementation

uses
  SysUtils,
  SyncObjs,
  Windows,
  uDZSysUtils,
  uDZTrace,
  uDZLogWritter,
  uAppCmdLineParams;

var
  lock: TSynchroObject;
  trace: ITrace;

procedure WriteLog(const s: string);
begin
  lock.Acquire();
  try
    trace.Write(tsInformation, s);
  finally
    lock.Release();
  end;
end;

procedure FmtWriteLog(const fmt: string; const args: array of const);
begin
  lock.Acquire();
  try
    trace.FormatWrite(tsInformation, fmt, args);
  finally
    lock.Release();
  end;
end;

initialization
  lock := TCriticalSection.Create();
  if (SameText(cmdLineParams.LogType, 'Console')) then
  begin
    Windows.AllocConsole();
    trace := TConsoleTrace.Create();
  end
  else
    trace := TMultiFileLogWritter.Create(
      ExtractFilePath(ParamStr(0)) + 'logs');
  trace.Attributes['Encoding'] := teAnsi;
  trace.Attributes['LogSeparate'] := dtpHour;
  trace.DateTimeFormat := 'hh:nn:ss';
  
finalization
  lock.Free();

end.
